import { INCREASE, DECREASE, GET_NEWS } from './actionType'

// 仓库数据
const defaultState = {
	count: 2,
	news: [{ name: '官官', id: 'guanguan' }],
}

const reducer = (state = defaultState, action) => {
	// reducer 不允许直接修改 state的数据
	const newState = { ...state }
	const { count = 0 } = state
	const { count: newCount = 0, news = [] } = action
	switch (action.type) {
		case INCREASE:
			newState.count = count + newCount
			break
		case DECREASE:
			newState.count = count - newCount
			break
		case GET_NEWS:
			newState.news = news
			break
		default:
			console.log('没有发现type', action.type)
			return state
	}
	return newState
}

export default reducer
